/*
*    Reversi Contender homepage:  http://code.google.com/p/reversi-contender
*
*    copyright 2011 steven sims <steven.joseph.sims at gmail.com>
*
*    This file is part of Reversi Contender.
*
*    Reversi Contender is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Reversi Contender is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with Reversi Contender.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.threadswarm.reversi.gui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import org.jdesktop.core.animation.timing.Animator;
import org.threadswarm.reversi.GameSession;
import org.threadswarm.reversi.gui.animation.AnimationType;
import org.threadswarm.reversi.gui.animation.AnimatorRepository;

/**
 *
 * @author steve
 */
public class CellClickActionListener implements MouseListener {

    private final List<CellComponent> panelList;
    private final CellComponent panel;
    private final GameSession prefs = GameSession.getInstance();

    public CellClickActionListener(CellComponent panel, List<CellComponent> panelList) {
        this.panel = panel;
        this.panelList = panelList;
    }

    @Override
    public void mouseClicked(MouseEvent me) {
        //
    }

    @Override
    public void mousePressed(MouseEvent me) {
        //
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        if(panel.isInsertable()){
            Animator availInsertionAnimator = AnimatorRepository.getInstance().getAnimator(AnimationType.AVAIL_INSERTION);
            availInsertionAnimator.stop();
            availInsertionAnimator.clearTargets();
            
            panel.insert(prefs.getPlayerStatus());
            for(CellComponent otherCell : panelList){
                otherCell.setInsertable(false);
            }
        }
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        //
    }

    @Override
    public void mouseExited(MouseEvent me) {
        //
    }

    

}
